/**
   Copyright 2011 Фроловский А. В.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   
   This file is a part of MyStats project
 */

/**
 * Data type
 */

package foo.mystats.model;

import android.content.Context;
import foo.mystats.R;

public class DataType {
	public static final int INTEGER = 1;
	public static final int REAL = 2;
	public static final int STRING = 3;
	public static final int BOOLEAN = 4;
	public static final int TIME = 5;

	private int type;
	private String name;

	public DataType(int _type, String _name) {
		setType(_type);
		setName(_name);
	}

	public DataType(int _type) {
		setType(_type);
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		if (type != INTEGER && type != REAL && type != STRING && type != BOOLEAN && type != TIME) {
			throw new IllegalArgumentException("Wrong data type specidified: " + type);
		}
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String _name) {
		this.name = _name;
	}

	public String toString() {
		return getName();
	}

	public static String typeToString(Context context, int _type) {
		switch (_type) {
		case INTEGER:
			return context.getString(R.string.datatype_integer);
		case REAL:
			return context.getString(R.string.datatype_real);
		case STRING:
			return context.getString(R.string.datatype_string);
		case BOOLEAN:
			return context.getString(R.string.datatype_boolean);
		case TIME:
			return context.getString(R.string.datatype_time);
		default:
			return null;
		}
	}
}
